home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / graphics / scalemod.frm < prev    next >
Text File  |  1993-05-16  |  11KB  |  333 lines

  1. VERSION 2.00
  2. Begin Form frmScaleMode 
  3.    Caption         =   "ScaleMode Display"
  4.    ClientHeight    =   3885
  5.    ClientLeft      =   405
  6.    ClientTop       =   1515
  7.    ClientWidth     =   4905
  8.    Height          =   4290
  9.    Left            =   345
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3885
  13.    ScaleWidth      =   4905
  14.    Top             =   1170
  15.    Width           =   5025
  16.    Begin PictureBox picDraw 
  17.       DragIcon        =   SCALEMOD.FRX:0000
  18.       Height          =   1935
  19.       Left            =   960
  20.       ScaleHeight     =   1905
  21.       ScaleWidth      =   2865
  22.       TabIndex        =   2
  23.       Top             =   720
  24.       Width           =   2895
  25.    End
  26.    Begin PictureBox picXaxis 
  27.       Height          =   255
  28.       Left            =   0
  29.       ScaleHeight     =   225
  30.       ScaleWidth      =   4665
  31.       TabIndex        =   1
  32.       Top             =   3600
  33.       Width           =   4695
  34.    End
  35.    Begin PictureBox picYAxis 
  36.       Height          =   3615
  37.       Left            =   4680
  38.       ScaleHeight     =   3585
  39.       ScaleWidth      =   225
  40.       TabIndex        =   0
  41.       Top             =   0
  42.       Width           =   255
  43.    End
  44. End
  45. Const DM_COPYPEN = 1
  46. Const DM_NOTXORPEN = 10
  47.  
  48. Dim oldCursorX As Single
  49. Dim oldCursorY As Single
  50. Dim bTracking As Integer
  51. Dim Anchor(1) As Single
  52. Dim bDrag As Integer
  53. Dim bFirst As Integer
  54.  
  55.  
  56.  
  57. Sub DrawCursorLocation (Source As Control, X As Single, Y As Single, OldRedraw As Integer, NewRedraw As Integer)
  58.     Dim fcolor As Long
  59.     Dim ii As Integer
  60.     Dim sParam As String
  61.     Dim oldDrawMode As Integer
  62.     Dim oldDrawWidth As Integer
  63.     Dim location As Single
  64.  
  65.     If True Then
  66.         'Redraw the X-Axis Cursor Marker
  67.         oldDrawMode = picXaxis.DrawMode
  68.         oldDrawWidth = picXaxis.DrawWidth
  69.         picXaxis.DrawMode = DM_NOTXORPEN      'Not XOR
  70.         picXaxis.DrawWidth = 2
  71.         'Redraw the old mark
  72.         If OldRedraw = True Then
  73.             location = picXaxis.ScaleWidth * (oldCursorX - Source.ScaleLeft) / Source.ScaleWidth - picXaxis.ScaleLeft
  74.             picXaxis.Line (location, 0)-(location, picXaxis.ScaleHeight)
  75.         End If
  76.         'Draw the new mark
  77.         If NewRedraw = True Then
  78.             location = picXaxis.ScaleWidth * (X - Source.ScaleLeft) / Source.ScaleWidth + picXaxis.ScaleLeft
  79.             picXaxis.Line (location, 0)-(location, picXaxis.ScaleHeight)
  80.         End If
  81.  
  82.         'Store the old Cursor locations and reset the Draw Properties
  83.         oldCursorX = X
  84.         picXaxis.DrawMode = oldDrawMode
  85.         picXaxis.DrawWidth = oldDrawWidth
  86.  
  87.         'Redraw the Y-Axis Cursor Marker
  88.         oldDrawMode = picXaxis.DrawMode
  89.         oldDrawWidth = picXaxis.DrawWidth
  90.         'Set DrawMode to NOTXORPEN
  91.         picYaxis.DrawMode = DM_NOTXORPEN      'Not XOR
  92.         picYaxis.DrawWidth = 2
  93.  
  94.         'Redraw the old mark
  95.         If OldRedraw = True Then
  96.             location = picYaxis.ScaleHeight * (oldCursorY - Source.ScaleTop) / Source.ScaleHeight - picYaxis.ScaleTop
  97.             picYaxis.Line (0, location)-(picYaxis.ScaleWidth, location)
  98.         End If
  99.  
  100.         If NewRedraw = True Then
  101.             'Draw the new mark
  102.             location = picYaxis.ScaleHeight * (Y - Source.ScaleTop) / Source.ScaleHeight + picYaxis.ScaleTop
  103.             picYaxis.Line (0, location)-(picYaxis.ScaleWidth, location)
  104.         End If
  105.         'Store the old Cursor locations and reset the Draw Properties
  106.         oldCursorY = Y
  107.         picYaxis.DrawMode = oldDrawMode
  108.         picYaxis.DrawWidth = oldDrawWidth
  109.     Else
  110.         ii = SetTextAlign(Source.hDC, TA_BOTTOM)
  111.         fcolor = Source.ForeColor
  112.         Source.ForeColor = Source.BackColor
  113.         Source.CurrentX = oldCursorX
  114.         Source.CurrentY = oldCursorY
  115.         Source.Print Tag
  116.         Source.ForeColor = fcolor
  117.         Source.CurrentX = X
  118.         Source.CurrentY = Y
  119.         oldCursorX = X
  120.         oldCursorY = Y
  121.         sParam = "(" + LTrim$(RTrim$(Str$(Int(X)))) + "," + LTrim$(RTrim$(Str$(Int(Y)))) + ")"
  122.         Source.Print sParam
  123.         Source.Tag = sParam
  124.     End If
  125. End Sub
  126.  
  127. Sub DrawXRuler (Source As Control, Ruler As Control)
  128.     Const MAJORINC = 10
  129.     Const MINORINC = 4
  130.     Dim ii As Integer
  131.     Dim jj As Integer
  132.     Dim numstr As String
  133.     Dim ScaleInterval As Single
  134.     Dim ScaleValue As Single
  135.     Dim MajorInt As Integer
  136.     Dim MinorInt As Integer
  137.  
  138.     'Initialize Ruler scale values
  139.     picXaxis.ScaleMode = 0      'User-defined
  140.     picXaxis.ScaleWidth = 1000
  141.     picXaxis.ScaleHeight = 100
  142.  
  143.     MajorInt = Ruler.ScaleWidth / MAJORINC
  144.     MinorInt = MajorInt / MINORINC
  145.  
  146.     ScaleValue = Source.ScaleLeft
  147.     ScaleInterval = Source.ScaleWidth / MAJORINC
  148.  
  149.     Ruler.Cls
  150.     start = Int(Ruler.ScaleLeft)
  151.     finish = Int(Ruler.ScaleLeft + Ruler.ScaleWidth)
  152.     For ii = start To finish Step MajorInt
  153.         numstr = LTrim$(RTrim$(Str$(Int(ScaleValue))))
  154.         Ruler.Line (ii, 0)-(ii, Ruler.ScaleHeight / 6)
  155.         Ruler.CurrentX = ii - Ruler.TextHeight(numstr) / 2
  156.         Ruler.CurrentY = Ruler.ScaleHeight / 6
  157.         Ruler.Print numstr
  158.         For jj = 1 To MINORINC
  159.             Ruler.Line (ii + MinorInt * jj, 0)-(ii + MinorInt * jj, Ruler.ScaleHeight / 8)
  160.         Next jj
  161.         ScaleValue = ScaleValue + ScaleInterval
  162.     Next ii
  163.  
  164.    If bFirst Then
  165.       oldDrawMode = picXaxis.DrawMode
  166.       oldDrawWidth = picXaxis.DrawWidth
  167.       'Set DrawMode to NOTXORPEN
  168.       picXaxis.DrawMode = DM_NOTXORPEN      'Not XOR
  169.       picXaxis.DrawWidth = 2
  170.       location = picXaxis.ScaleWidth * (oldCursorX - ScaleLeft) / ScaleWidth + picXaxis.ScaleLeft
  171.       picXaxis.Line (location, 0)-(location, picXaxis.ScaleHeight)
  172.       picXaxis.DrawMode = oldDrawMode
  173.       picXaxis.DrawWidth = oldDrawWidth
  174.    End If
  175. End Sub
  176.  
  177. Sub DrawYRuler (Source As Control, Ruler As Control)
  178.     Const MAJORINC = 10
  179.     Const MINORINC = 4
  180.     Dim ii As Integer
  181.     Dim jj As Integer
  182.     Dim numstr As String
  183.     Dim ScaleInterval As Single
  184.     Dim ScaleValue As Single
  185.     Dim MajorInt As Integer
  186.     Dim MinorInt As Integer
  187.  
  188.     picYaxis.ScaleMode = 0      'User-defined
  189.     picYaxis.ScaleWidth = 100
  190.     picYaxis.ScaleHeight = 1000
  191.  
  192.     MajorInt = Ruler.ScaleHeight / MAJORINC
  193.     MinorInt = MajorInt / MINORINC
  194.  
  195.     ScaleValue = Source.ScaleTop
  196.     ScaleInterval = Source.ScaleHeight / MAJORINC
  197.  
  198.     Ruler.Cls
  199.  
  200.     For ii = Int(Ruler.ScaleTop) To Int(Ruler.ScaleTop + Ruler.ScaleHeight) Step MajorInt
  201.         numstr = LTrim$(RTrim$(Str$(Int(ScaleValue))))
  202.         Ruler.Line (0, ii)-(Ruler.ScaleWidth / 6, ii)
  203.         Ruler.CurrentX = Ruler.ScaleWidth / 6
  204.         Ruler.CurrentY = ii - Ruler.TextHeight(numstr) / 2
  205.         Ruler.Print numstr
  206.         For jj = 1 To MINORINC
  207.             Ruler.Line (0, ii + MinorInt * jj)-(Ruler.ScaleWidth / 8, ii + MinorInt * jj)
  208.         Next jj
  209.         ScaleValue = ScaleValue + ScaleInterval
  210.     Next ii
  211.  
  212.    If bFirst Then
  213.       oldDrawMode = picXaxis.DrawMode
  214.       oldDrawWidth = picXaxis.DrawWidth
  215.       'Set DrawMode to NOTXORPEN
  216.       picYaxis.DrawMode = 10      'Not XOR
  217.       picYaxis.DrawWidth = 2
  218.       location = picYaxis.ScaleHeight * (oldCursorY - ScaleTop) / ScaleHeight + picYaxis.ScaleTop
  219.       picYaxis.Line (0, location)-(picYaxis.ScaleWidth, location)
  220.       picYaxis.DrawMode = oldDrawMode
  221.       picYaxis.DrawWidth = oldDrawWidth
  222.    End If
  223. End Sub
  224.  
  225. Sub Form_Load ()
  226.     'Initialize Ruler Locations
  227.     picYaxis.Width = 455
  228.     picXaxis.Height = 255
  229.     picDraw.Width = frmScaleMode.Width - picYaxis.Width
  230.     picDraw.Height = frmScaleMode.Height - picXaxis.Height
  231.  
  232.     'Initialize Ruler scale values
  233.     picXaxis.ScaleMode = 0      'User-defined
  234.     picXaxis.ScaleWidth = 1000
  235.     picXaxis.ScaleHeight = 100
  236.     picYaxis.ScaleMode = 0      'User-defined
  237.     picYaxis.ScaleWidth = 100
  238.     picYaxis.ScaleHeight = 1000
  239.  
  240.     'Initialize Ruler fonts
  241.     picXaxis.FontName = "Arial"
  242.     picXaxis.FontSize = 6
  243.     picYaxis.FontName = "Arial"
  244.     picYaxis.FontSize = 6
  245.  
  246.     oldCursorX = 0
  247.